import abc

from .dock import DockPlugin


class RunningTaskPlugin(abc.ABC):
    def on_before_run(self):
        pass

    def on_after_run(self):
        pass


class RunningTask(DockPlugin, abc.ABC):
    def run(self):
        self._before_run()
        self._run()
        self._after_run()

    def _before_run(self):
        self.dock.scan_call_plugins(
            self.dock.iter_plugins(RunningTaskPlugin),
            lambda plugin: plugin.on_before_run())

    @abc.abstractmethod
    def _run(self):
        pass

    def _after_run(self):
        self.dock.scan_call_plugins(
            self.dock.iter_plugins(RunningTaskPlugin),
            lambda plugin: plugin.on_after_run())
